package br.com.absolutech.study.chapter9.pag415;

import java.util.ArrayList;
import java.util.List;

public class Machine extends Thread {

	List<MachineInstructions> jobs = new ArrayList<MachineInstructions>();

	public void addJob(MachineInstructions job) {
		synchronized (jobs) {
			jobs.add(job);
			jobs.notify();
		}
	}

	public void run() {
		while (true) {
			synchronized (jobs) {
				//espera ateh que pelo menos um job esteja disponivel
				while (jobs.isEmpty()) {
					try {
						jobs.wait();
					} catch (InterruptedException ie) {
					}
				}
				//se chegarmos aqui, saberemos que jobs nao esta vazio
				MachineInstructions instructions = jobs.remove(0);
				//(enviaria as instrucoes da maquina para o hardware)
			}
		}
	}
}

class MachineInstructions {

	private String description;

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}


}
